<?php
require('paymentPlugin.php');
class pay_ccb extends paymentPlugin{

    var $name = '中国建设银行';//工商银行
    var $logo = 'CCB';
    var $version = 20070902;
    var $charset = 'gbk';
    var $submitUrl = 'https://ibsbjstar.ccb.com.cn/app/ccbMain'; //正式地址
    var $submitButton = 'http://img.alipay.com/pimg/button_alipaybutton_o_a.gif'; ##需要完善的地方
    var $supportCurrency = array("CNY"=>"001");
    var $supportArea = array("AREA_CNY");
    var $intro = "中国建设银行网上银行";
    var $orderby = '';
    var $head_charset="gbk";

    function toSubmit($payment){
        $merId = $this->getConf($payment["M_OrderId"], 'member_id');
        $keyPass = $this->getConf($payment["M_OrderId"], 'keyPass');
        $icbcno = $this->getConf($payment["M_OrderId"],'icbcno');
        $icbcFile = $this->getConf($payment["M_OrderId"],'icbcFile');
        $keyFile = $this->getConf($payment["M_OrderId"],'keyFile');
        $certFile = $this->getConf($payment["M_OrderId"],'certFile');
        $charset = $this->system->loadModel('utility/charset');

				$return['MERCHANTID'] = $this->getConf($payment["M_OrderId"], 'merchantid');
				$return['POSID'] = $this->getConf($payment["M_OrderId"], 'posid');
				$return['BRANCHID'] = $this->getConf($payment["M_OrderId"], 'branchid');
				$return['ORDERID'] = $payment['M_OrderId'];
				$return['PAYMENT'] = number_format($payment['M_Amount'],2,".","");
				$return['CURCODE'] = '01';
				$return['TXCODE'] = '520100';
				$return['REMARK1'] = '';
				$return['REMARK2'] = '';
				//$return['PUB32'] = '30819c300d06092a864886f70d0101';

				foreach($return as $key=>$val){
					$signstr .= $key.'='.$val.'&';
				}

				$signstr = trim($signstr,'&');

				//die($signstr);
				
				$return['MAC'] = md5($signstr);
				
				//pub32不参与网际传递
				//unset($return['PUB32']);
       
        return $return;
    }

    function callback($in,&$paymentId,&$money,&$message,&$tradeno){
				  
				$strSrc=$in['src'];
				$strSign=$in['sign'];
				$strPubKey=$in['pubkey'];	

				$paymentId = $in['ORDERID'];
				$money = $in['PAYMENT'];
				$tradeno = $paymentId;
				
/*
        if (strtoupper(substr(PHP_OS,0,3))=="WIN"){
					$rsasig=new COM("CCBRSA.RSASig");
					$rsasig->setpublickey($strPubKey);
					$strRet=$rsasig->StringVerifySigature($strSign,$strSrc);
        }
        else{
					$strRet = true;
        }
*/

				$isok = 0;

        if ($isok == 0){             
            
            if ($in['SUCCESS'] == 'Y'){
                $message="支付成功！";
                return PAY_SUCCESS;
            }
            else{
                $message = "支付失败！";
                return PAY_FAILED;
            }
        }else{
            $message = "验证签名错误！";
            return PAY_ERROR;
        }
    }

    function getfields(){
            return array(
                'merchantid'=>array(
                     'label'=>'商户代码',
                     'type'=>'string',
                     'helpMsg'=>'申请时，由建行发放'
                 ),
                 'posid'=>array(
                     'label'=>'商户柜台代码',
                     'type'=>'string',
										 'helpMsg'=>'申请时，由建行发放',
                 ),
								'branchid'=>array(
                     'label'=>'分行代码',
                     'type'=>'string',
										 'helpMsg'=>'申请时，由建行发放',
                 )
                 
            );
    }
}
?>
